﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DataInfo;
using XBLib.Dal;
using XBLib.Dal.AdoDal;
using XBLib.BusinessObject;
using System.Data.Common;
using KenLib.BusinessObject;
using KenLib.BusinessManager;
using System.Web;

namespace KenLib.Dal
{
    public class 面接情報Dao : BaseAdoDao
    {
        #region //Thanh Dong
        public int frmJ_TraineeListSelectCheck_Insert_面接情報(面接情報 _面接情報, out int ID)
        {
            ID = 0;
            DbParameter dbparam1 = _daoHelper.CreateParameter("@面接日", _面接情報.面接日, DbType.DateTime);
            DbParameter dbparam2 = _daoHelper.CreateParameter("@ID", -1);
            dbparam2.Direction = ParameterDirection.Output;
            DbCommand dbcomman = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_TraineeListSelectCheck_Insert_面接情報_Dong, CommandType.StoredProcedure, dbparam1, dbparam2);
            _daoHelper.Execute(dbcomman);
            ID = (int)dbcomman.Parameters["@ID"].Value;
            return ID;
        }

        public int frmJ_CandidateSendEmail_Update面接情報(面接情報 _面接情報)
        {
            DbParameter dbparam1 = _daoHelper.CreateParameter("@ID", _面接情報.ID, DbType.Int32);
            DbParameter dbparam2 = _daoHelper.CreateParameter("@内容", _面接情報.内容, DbType.String);
            DbParameter dbparam3 = _daoHelper.CreateParameter("@来社日", _面接情報.来社日, DbType.DateTime);
            DbParameter dbparam4 = _daoHelper.CreateParameter("@来社時期", _面接情報.来社時期, DbType.String);
            DbParameter dbparam5 = _daoHelper.CreateParameter("@場所", _面接情報.場所, DbType.String);
            DbParameter dbparam6 = _daoHelper.CreateParameter("@持参物", _面接情報.持参物, DbType.String);
            DbParameter dbparam7 = _daoHelper.CreateParameter("@問い合わせ先", _面接情報.問い合わせ先, DbType.String);

            DbCommand dbcomman = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_CandidateSendEmail_Update面接情報_Dong, CommandType.StoredProcedure, dbparam1, dbparam2, dbparam3, dbparam4, dbparam5, dbparam6, dbparam7);
            return _daoHelper.Execute(dbcomman);
        }

        public DataTable frmJ_CandidateSendEmail_GetByID(DateTime 面接日, int 団体ID, int 企業ID)
        {
            DbParameter dbpram1 = _daoHelper.CreateParameter("@面接日", 面接日, DbType.DateTime);
            DbParameter dbpram2 = _daoHelper.CreateParameter("@団体ID", 団体ID, DbType.Int32);
            DbParameter dbpram3 = _daoHelper.CreateParameter("@企業ID", 企業ID, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_CandidateSendEmail_GetByID_Dong, CommandType.StoredProcedure, dbpram1, dbpram2, dbpram3);
            return _daoHelper.Query(dbcommand);
        }

        public int frmJ_CandidateSendEmail_Insert_Transaction(面接情報 _面接情報, int 団体ID, int 企業ID, DataTable dt, DataTable dt2, 面接情報 _面接情報1)
        {
            // Data correct
            int flag = 1;
            DbConnection dbconnect = _daoHelper.GetConnection();
            dbconnect.Open();
            DbTransaction dbtransaction = dbconnect.BeginTransaction();
            _daoHelper.Transaction = dbtransaction;
            _daoHelper.Connect = dbconnect;
            try
            {
                
                DbParameter dbparam1 = _daoHelper.CreateParameter("@面接日", _面接情報.面接日, DbType.DateTime);
                DbParameter dbparam2 = _daoHelper.CreateParameter("@ID", -1);
                dbparam2.Direction = ParameterDirection.Output;
                DbCommand dbcomman = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_TraineeListSelectCheck_Insert_面接情報_Dong, CommandType.StoredProcedure, dbparam1, dbparam2);
                //_daoHelper.Execute(dbcomman);
                
                if (_daoHelper.Execute(dbcomman) == 1)
                {
                    int ID = (int)dbcomman.Parameters["@ID"].Value;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        int 応募情報ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                        string 面接番号 = str面接番号(i + 1);
                        面接詳細情報 _面接詳細情報 = get面接詳細情報(ID, 団体ID, 企業ID, 応募情報ID, 面接番号);
                        DbParameter dbParam3 = _daoHelper.CreateParameter("@ID", _面接詳細情報.ID, DbType.Int32);
                        DbParameter dbParam4 = _daoHelper.CreateParameter("@団体ID", _面接詳細情報.団体ID, DbType.Int32);
                        DbParameter dbParam5 = _daoHelper.CreateParameter("@企業ID", _面接詳細情報.企業ID, DbType.Int32);
                        DbParameter dbParam6 = _daoHelper.CreateParameter("@応募情報ID", _面接詳細情報.応募情報ID, DbType.Int32);
                        DbParameter dbParam7 = _daoHelper.CreateParameter("@面接番号", _面接詳細情報.面接番号, DbType.String);
                        DbCommand dbcommand1 = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_TraineeListSelectCheck_Insert_面接詳細情報_Dong, CommandType.StoredProcedure, dbParam3, dbParam4, dbParam5, dbParam6, dbParam7);
                        if (_daoHelper.Execute(dbcommand1) != 1)
                        {
                            dbtransaction.Rollback();
                            dbconnect.Close();
                            flag = 1;
                            return flag;
                        }
                    }
                    _面接情報1.ID = ID;
                    //_面接情報1.ID = 1000;
                    DbParameter dbparam8 = _daoHelper.CreateParameter("@ID", _面接情報1.ID, DbType.Int32);
                    DbParameter dbparam9 = _daoHelper.CreateParameter("@内容", _面接情報1.内容, DbType.String);
                    DbParameter dbparam10 = _daoHelper.CreateParameter("@来社日", _面接情報1.来社日, DbType.DateTime);
                    DbParameter dbparam11 = _daoHelper.CreateParameter("@来社時期", _面接情報1.来社時期, DbType.String);
                    DbParameter dbparam12 = _daoHelper.CreateParameter("@場所", _面接情報1.場所, DbType.String);
                    DbParameter dbparam13 = _daoHelper.CreateParameter("@持参物", _面接情報1.持参物, DbType.String);
                    DbParameter dbparam14 = _daoHelper.CreateParameter("@問い合わせ先", _面接情報1.問い合わせ先, DbType.String);

                    DbCommand dbcomman2 = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_CandidateSendEmail_Update面接情報_Dong, CommandType.StoredProcedure, dbparam8, dbparam9, dbparam10, dbparam11, dbparam12, dbparam13, dbparam14);
                    if (_daoHelper.Execute(dbcomman2) != 1)
                    {
                        dbtransaction.Rollback();
                        dbconnect.Close();
                        flag = 1;
                        return flag;
                    }
                }
                else
                {
                    dbtransaction.Rollback();
                    dbconnect.Close();
                    flag = 1;
                    return flag;
                }
               
               
                dbtransaction.Commit();
                dbconnect.Close();
                flag = 0;
                return flag;
            }
            catch 
            {
                dbtransaction.Rollback();
                dbconnect.Close();
                flag = 1;
                return flag;
            }

            //return flag;
        }


        public int frmJ_CandidateSendEmail_Update_Transaction(DateTime 面接日, int 団体ID, int 企業ID, DataTable dt, DataTable dt1, DataTable dt2, 面接情報 _面接情報1)
        {
            int flag = 1;
            DbConnection dbconnect = _daoHelper.GetConnection();
            dbconnect.Open();
            DbTransaction dbtransaction = dbconnect.BeginTransaction();
            _daoHelper.Transaction = dbtransaction;
            _daoHelper.Connect = dbconnect;
            try
            {
                int ID = Convert.ToInt32(dt.Rows[0]["ID"]);
                //int ID = 1000;
                DbParameter dbparam1 = _daoHelper.CreateParameter("@ID", ID, DbType.Int32);
                DbCommand dbcommand1 = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_CandidateSendEmail_Delete_面接詳細情報_Dong, CommandType.StoredProcedure, dbparam1);
                _daoHelper.Execute(dbcommand1);
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    int 応募情報ID = Convert.ToInt32(dt1.Rows[i]["ID"]);
                    string 面接番号 = str面接番号(i + 1);
                    面接詳細情報 _面接詳細情報 = get面接詳細情報(ID, 団体ID, 企業ID, 応募情報ID, 面接番号);
                    DbParameter dbParam2 = _daoHelper.CreateParameter("@ID", _面接詳細情報.ID, DbType.Int32);
                    DbParameter dbParam3 = _daoHelper.CreateParameter("@団体ID", _面接詳細情報.団体ID, DbType.Int32);
                    DbParameter dbParam4 = _daoHelper.CreateParameter("@企業ID", _面接詳細情報.企業ID, DbType.Int32);
                    DbParameter dbParam5 = _daoHelper.CreateParameter("@応募情報ID", _面接詳細情報.応募情報ID, DbType.Int32);
                    DbParameter dbParam6 = _daoHelper.CreateParameter("@面接番号", _面接詳細情報.面接番号, DbType.String);
                    DbCommand dbcommand2 = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_TraineeListSelectCheck_Insert_面接詳細情報_Dong, CommandType.StoredProcedure, dbParam2, dbParam3, dbParam4, dbParam5, dbParam6);
                    //_daoHelper.Execute(dbcommand2);
                    if (_daoHelper.Execute(dbcommand2) != 1)
                    {
                        dbtransaction.Rollback();
                        dbconnect.Close();
                        flag = 1;
                        return flag;
                    }
                }
                _面接情報1.ID = ID;
                DbParameter dbparam7 = _daoHelper.CreateParameter("@ID", _面接情報1.ID, DbType.Int32);
                DbParameter dbparam8 = _daoHelper.CreateParameter("@内容", _面接情報1.内容, DbType.String);
                DbParameter dbparam9 = _daoHelper.CreateParameter("@来社日", _面接情報1.来社日, DbType.DateTime);
                DbParameter dbparam10 = _daoHelper.CreateParameter("@来社時期", _面接情報1.来社時期, DbType.String);
                DbParameter dbparam11 = _daoHelper.CreateParameter("@場所", _面接情報1.場所, DbType.String);
                DbParameter dbparam12 = _daoHelper.CreateParameter("@持参物", _面接情報1.持参物, DbType.String);
                DbParameter dbparam13 = _daoHelper.CreateParameter("@問い合わせ先", _面接情報1.問い合わせ先, DbType.String);

                DbCommand dbcomman3 = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_CandidateSendEmail_Update面接情報_Dong, CommandType.StoredProcedure, dbparam7, dbparam8, dbparam9, dbparam10, dbparam11, dbparam12, dbparam13);
                if (_daoHelper.Execute(dbcomman3) != 1)
                {
                    dbtransaction.Rollback();
                    dbconnect.Close();
                    flag = 1;
                    return flag;
                }
                
                dbtransaction.Commit();
                dbconnect.Close();
                flag = 0;
                return flag;
            }
            catch
            {
                dbtransaction.Rollback();
                dbconnect.Close();
                flag = 1;
                return flag;
            }
            //return flag;
        }
        
        
        public 面接詳細情報 get面接詳細情報(int ID, int 団体ID, int 企業ID, int 応募情報ID, string 面接番号)
        {
            面接詳細情報 _面接詳細情報 = new 面接詳細情報();
            _面接詳細情報.ID = ID;
            _面接詳細情報.団体ID = 団体ID;
            _面接詳細情報.企業ID = 企業ID;
            _面接詳細情報.応募情報ID = 応募情報ID;
            _面接詳細情報.面接番号 = 面接番号;
            return _面接詳細情報;
        }

        public string str面接番号(int temp)
        {
            string kq = "";
            if (temp < 10)
            {
                kq = "0" + Convert.ToString(temp);
            }
            else
            {
                kq = Convert.ToString(temp);
            }
            return kq;
        }

        public DataTable frmJ_TraineeAppAssignCheck_面接日(int 団体ID, int 企業ID)
        { 
            DbParameter dbpram1 = _daoHelper.CreateParameter("@団体ID", 団体ID, DbType.Int32);
            DbParameter dbpram2 = _daoHelper.CreateParameter("@企業ID", 企業ID, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_TraineeAppAssignCheck_面接日_Dong, CommandType.StoredProcedure, dbpram1, dbpram2);
            return _daoHelper.Query(dbcommand);
        }

		public DataTable frmJ_InterviewResultSearch_面接日(int 団体ID, int 企業ID)
		{
			DbParameter dbpram1 = _daoHelper.CreateParameter("@団体ID", 団体ID, DbType.Int32);
			DbParameter dbpram2 = _daoHelper.CreateParameter("@企業ID", 企業ID, DbType.Int32);
			DbCommand dbcommand = _daoHelper.CreateCommand("sp_frmJ_InterviewResultSearch_面接日_Hunglt", CommandType.StoredProcedure, dbpram1, dbpram2);
			return _daoHelper.Query(dbcommand);
		}

        #endregion
        #region Phuong
        public DataTable sp_frmJ_TestResultInput_dll面接日()
        {

            DbCommand dbcomman = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_TestResultInput_dll面接日, CommandType.StoredProcedure);
            return _daoHelper.Query(dbcomman);
        }

        #endregion

        #region Hunglt
        public DataTable Select面接日()
        {
            DbCommand dbcomman = _daoHelper.CreateCommand("sp_select_面接日_Hunglt", CommandType.StoredProcedure);
            return _daoHelper.Query(dbcomman);
        }
        public DataTable LoadInfo面接情報(int value_id)
        {
            DbParameter dbparam = _daoHelper.CreateParameter("@ID", value_id, DbType.Int32);
            DbCommand dbcomman = _daoHelper.CreateCommand("sp_select_面接情報_Hunglt", CommandType.StoredProcedure, dbparam);
            return _daoHelper.Query(dbcomman);
        }
        public int UpdateInfo面接情報(面接情報 obj, int 役, int button_type)
        {
            try
            {
                DbParameter dbparamID = _daoHelper.CreateParameter("@ID", obj.ID, DbType.Int32);
                DbParameter dbparam来社日2 = _daoHelper.CreateParameter("@来社日2", obj.来社日2, DbType.DateTime);
                DbParameter dbparam来社時期2 = _daoHelper.CreateParameter("@来社時期2", obj.来社時期2, DbType.String);
                DbParameter dbparam場所2 = _daoHelper.CreateParameter("@場所2", obj.場所2, DbType.String);
                DbParameter dbparam持参物2 = _daoHelper.CreateParameter("@持参物2", obj.持参物2, DbType.String);
                DbParameter dbparam問い合わせ先2 = _daoHelper.CreateParameter("@問い合わせ先2", obj.問い合わせ先2, DbType.String);
                DbParameter dbparam内容2 = _daoHelper.CreateParameter("@内容2", obj.内容2, DbType.String);
                DbParameter dbparam役 = _daoHelper.CreateParameter("@役", 役, DbType.Int32);
                DbParameter dbparamButton_Type = _daoHelper.CreateParameter("@Button_Type", button_type, DbType.Int32);

                DbCommand dbcomman = _daoHelper.CreateCommand("sp_Update_面接情報_役_2_Hunglt", CommandType.StoredProcedure,
                    dbparamID, dbparam来社日2, dbparam来社時期2, dbparam場所2, dbparam持参物2, dbparam問い合わせ先2, dbparam内容2,
                    dbparam役, dbparamButton_Type);

                _daoHelper.Execute(dbcomman);
                return 1;
            }
            catch {
                return 0;
            }
        }   
        public DataTable SelectMail面接情報(int value_id)
        {
            DbParameter dbparam = _daoHelper.CreateParameter("@ID", value_id, DbType.Int32);
            DbCommand dbcomman = _daoHelper.CreateCommand("sp_Select_面接情報_Email_Hunglt", CommandType.StoredProcedure, dbparam);
            return _daoHelper.Query(dbcomman);
        }
        #endregion
    }
}

